/**
 * 公平的糖果交换
 *
 * @USER: Administrator
 * @DATE: 2024/9/18 下午8:14
 * @VERSION: 1.0.0
 */
public class LC888 {
    public int[] fairCandySwap(int[] aliceSizes, int[] bobSizes) {
        int aliceCount = 0, bobCount = 0;
        int[] result = new int[2];
        for (int aliceSize : aliceSizes) {
            aliceCount += aliceSize;
        }
        for (int bobSize : bobSizes) {
            bobCount += bobSize;
        }
        int sub = aliceCount - bobCount;
        for (int i = 0; i < aliceSizes.length; i++) {
            if (contains(bobSizes, aliceSizes[i]-sub/2)>0) {
                result[0] = aliceSizes[i];
                result[1] = contains(bobSizes, aliceSizes[i]-sub/2);
            }
        }
        return result;
    }

    public int contains(int[] nums, int target) {
        for (int num : nums) {
            if (num == target) {
                return target;
            }
        }
        return -1;
    }

}
